package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.AdvMembersaddr;
import com.ruoyi.service.IAdvMembersaddrService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Controller
 *
 * @author ruoyi
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/system/membersaddr")
public class AdvMembersaddrController extends BaseController
{
    @Autowired
    private IAdvMembersaddrService advMembersaddrService;

    /**
     * 查询列表
     */

    @PreAuthorize("@ss.hasPermi('system:membersaddr:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdvMembersaddr advMembersaddr)
    {
        startPage();
        List<AdvMembersaddr> list = advMembersaddrService.selectAdvMembersaddrList(advMembersaddr);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */

    @PreAuthorize("@ss.hasPermi('system:membersaddr:export')")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdvMembersaddr advMembersaddr)
    {
        List<AdvMembersaddr> list = advMembersaddrService.selectAdvMembersaddrList(advMembersaddr);
        ExcelUtil<AdvMembersaddr> util = new ExcelUtil<AdvMembersaddr>(AdvMembersaddr.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */

    @PreAuthorize("@ss.hasPermi('system:membersaddr:query')")
    @GetMapping(value = "/{advMembersaddrId}")
    public AjaxResult getInfo(@PathVariable("advMembersaddrId") Long advMembersaddrId)
    {
        AdvMembersaddr advMembersaddr = advMembersaddrService.selectAdvMembersaddrByAdvMembersaddrId(advMembersaddrId);
        System.out.println("获取到的地址: " + advMembersaddr);
        return success(advMembersaddr);
    }

    /**
     * 新增
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('system:membersaddr:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdvMembersaddr advMembersaddr)
    {
        System.out.println(advMembersaddr);
        return toAjax(advMembersaddrService.insertAdvMembersaddr(advMembersaddr));
    }

    /**
     * 修改
     */

    @PreAuthorize("@ss.hasPermi('system:membersaddr:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdvMembersaddr advMembersaddr)
    {
        return toAjax(advMembersaddrService.updateAdvMembersaddr(advMembersaddr));
    }

    /**
     * 删除
     */

    @PreAuthorize("@ss.hasPermi('system:membersaddr:remove')")
    @Log(title = "", businessType = BusinessType.DELETE)
	@DeleteMapping("/{advMembersaddrIds}")
    public AjaxResult remove(@PathVariable Long[] advMembersaddrIds)
    {
        return toAjax(advMembersaddrService.deleteAdvMembersaddrByAdvMembersaddrIds(advMembersaddrIds));
    }
}
